import { BaseEntity } from '@/modules/core/base/BaseEntity';
import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToOne,
  OneToMany,
} from 'typeorm';
import { ORDER_STATUS } from '../contance';
import { OrderGoodEntity } from './order_good.entity';
import { UserEntity } from '@/modules/User/entities';

@Entity('order')
export class OrderEntity extends BaseEntity {
  @Column({
    comment: '订单状态',
    default: ORDER_STATUS.no_pay,
  })
  status: ORDER_STATUS;

  @Column({ comment: '总价' })
  total_price: number;

  @Column({ comment: '过期时间', nullable: true })
  expire_time: Date;

  @CreateDateColumn({
    comment: '下单时间',
  })
  ceate_time: Date;

  @OneToMany((type) => OrderGoodEntity, (order_good) => order_good.order, {
    onDelete: 'CASCADE',
  })
  orderGood: OrderGoodEntity;

  @ManyToOne((type) => UserEntity, (user) => user.order, {
    onDelete: 'CASCADE',
  })
  user: UserEntity;
}
